﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PinCity.Models.Base;

namespace PinCity.Models.Repositories
{
    /// <summary>
    /// Basic interface, that declares methods for operating on
    /// entities. Any operations with entities should be executed
    /// through this interface. This is the part of "Repository" pattern. 
    /// </summary>
    /// <typeparam name="T">A class, that derives from Entity.</typeparam>
    interface IRepository<T> where T: Entity
    {
        /// <summary>
        /// Saves new entity to the repository or updates an existing one.
        /// </summary>
        /// <param name="entity">An entity to save or update.</param>
        void SaveOrUpdate(T entity);

        /// <summary>
        /// Deletes an existing entity from repository.
        /// </summary>
        /// <param name="entity">A valid entity to delete.</param>
        void Delete(T entity);

        /// <summary>
        /// Deletes an exsisting entity by its ID.
        /// </summary>
        /// <param name="id">Identifier of existing entity.</param>
        void Delete(uint id);

        /// <summary>
        /// Get an existing entity from repository, given its ID.
        /// </summary>
        /// <param name="id">An ID of existing entity.</param>
        /// <returns>An entity or null, if none found.</returns>
        T Get(uint id);

        /// <summary>
        /// Gets all entities from the repository.
        /// </summary>
        /// <returns>IList of entities.</returns>
        IList<T> GetAll();

        /// <summary>
        /// Checks, if an entity with such id is persisted
        /// in this repository.
        /// </summary>
        /// <param name="id">ID of entity.</param>
        /// <returns>True, if entity is found.</returns>
        bool Contains(uint id);

        /// <summary>
        /// Initialize repository, fill it with predefined data.
        /// </summary>
        void Initialize();
    }
}
